<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>箭头函数和this</title>
</head>
<body>
    <div class="button">click</div>

    <script>
        function Timer() {
            this.s1 = 0;
            this.s2 = 0;

            let that = this;

            setInterval(function() {
                that.s1 ++;
                // console.log('传统函数', that.s1);
                // console.log(that    );
            }, 1000);

            setInterval(() => {
                this.s2 ++;
                // console.log('箭头函数', this.s2);
            }, 1000)
        }

        const time = new Timer();
        
        setTimeout(()=> console.log(time.s1), 3100);
        setTimeout(() => console.log(time.s2), 3100);

        function foo() {
            return () => {
                return () => {
                    return () => {
                        return () => {
                            console.log(this.id);
                            // console.log(id);
                        }
                    }
                }
            }
        }

        const f = foo.call({id: 1});
        const t1 = f.call({id: 2})()()();
        const t2 = f().call({id:3})()();


        function Cat() {
            live = 0;
            jumps:()=>{
                this.live++;
                console.log(this.live);
            }
        }
    </script>
</body>
</html>